// import { getExecutorList } from "@/api/modules/operation";
import { queryUserList } from "@/api/modules/fab";
import { formatAccountName } from "@/utils/common";

/**
 * @description: 获取search配置信息
 * @return {Array<CommonSearch.SearchOption>}
 */
export const useSearchOption = (): Array<CommonSearch.SearchOption> => {
  const workOrderNo: CommonSearch.SearchOption = {
    label: "工单号",
    key: "workOrderNo",
    value: "",
    type: "input",
    placeholder: "请输入工单号",
    span: 5
  };
  const creator: CommonSearch.SearchOption = {
    label: "创建人",
    key: "creator",
    value: "",
    type: "select",
    remote: true,
    // selectRemoteApi: getExecutorList,
    // getParams: (realName: string) => ({ realName }),
    // mapOption: ({ realName: label = null, userId: value = null }) => ({ label, value }),
    selectRemoteApi: queryUserList,
    // getParams: (usernameLike: string) => ({ usernameLike, page: 1, pageSize: 9999 }), //  账号查询
    getParams: (realNameLike: string) => ({ realNameLike, page: 1, pageSize: 9999 }), //  姓名查询
    formatOption: (res: any) =>
      res?.data?.map(({ userId: value, username = "", realName = "" }: any) => ({ value, label: formatAccountName(username, realName) })),
    placeholder: "请输入创建人",
    span: 5
  };
  // const executor: CommonSearch.SearchOption = {
  //   label: "责任人",
  //   key: "executor",
  //   value: "",
  //   type: "select",
  //   remote: true,
  //   selectRemoteApi: getExecutorList,
  //   getParams: (keywords: string) => ({ keywords }),
  //   mapOption: ({ realName: label = null, userId: value = null }) => ({ label, value }),
  //   placeholder: "请输入责任人"
  // };
  const taskStatus: CommonSearch.SearchOption = {
    label: "工单状态",
    key: "taskStatus",
    value: "",
    type: "select",
    typeCode: "gas_task_status",
    placeholder: "请选择工单状态",
    span: 5
  };
  const startTime: CommonSearch.SearchOption = {
    label: "创建日期",
    key: "startTime",
    realKeys: ["startTime", "endTime"],
    value: [],
    type: "daterange",
    span: 5
  };

  return [workOrderNo, creator, taskStatus, startTime];
};

/**
 * @description:  获取table表格的表头（cloumns）信息
 * @param {boolean} flag
 * @return {*}
 */
export const useTableCloumns = (cb?: (scope: any) => void): Array<CommonTable.TableCloumnsType> => {
  const tagMapOption = new Map([
    [
      1,
      {
        value: 1,
        label: "执行中",
        color: "#3B82F6FF"
      }
    ],
    [
      2,
      {
        value: 2,
        label: "已完成",
        color: "#10B981FF"
      }
    ]
  ]);

  const o_1 = {
    label: "工单号",
    prop: "workOrderNo",
    width: 130,
    cloumnClick(scope: any) {
      cb && cb(scope);
    }
  };
  const o_2 = {
    label: "状态",
    prop: "taskStatus",
    width: 130,
    tagMapOption,
    tagType: "point",
    defaultTagValue: 1,
    mapRow: ({ row: { taskStatus: value = "", taskStatusDesc: label = "" } }: any) => ({ value, label })
  };
  const o_2_2 = { label: "设备编号", prop: "deviceCode", width: 130 };
  const o_2_3 = { label: "设备地点", prop: "location", width: 130 };
  const o_3 = { label: "创建人", prop: "creatorName", width: 120 };
  const o_4 = { label: "责任人", prop: "executorName", width: 120 };
  const o_5 = { label: "创建时间", prop: "createTime", width: 130 };
  const o_6 = { label: "完成时间", prop: "completedTime", width: 130 };
  const o_7 = { label: "用时", prop: "takeTime", width: 60 };
  return [o_1, o_2, o_2_2, o_2_3, o_3, o_4, o_5, o_6, o_7];
};
